package com.mfdm.gui.views;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.part.ViewPart;

import com.mfdm.gui.serversimulator.Song;
import com.mfdm.gui.utils.ResourcesUtils;

public class ContentObjectViews extends ViewPart implements SongObserver {

	private static final String EDIT_ACTION_IMAGE_PATH = "icons/editAction2.gif";

	private Color m_color; 
	
	public static final String ID = "my-documents-management.objectcontent";

	private Label m_songContentLabel;
	
	private Action m_editAction;

	
	@Override
	public void createPartControl(Composite parent) {
		m_color = new Color(this.getSite().getShell().getDisplay(), 255, 255, 255);
		
		// set background color
		parent.setBackground(m_color);
		
		parent.setLayout(new RowLayout());
		
		m_songContentLabel = new Label(parent, SWT.NONE);
		m_songContentLabel.setText("Song contents                                            ");
		m_songContentLabel.setBackground(m_color);
		
		
		createActions(parent);
	}

	private void createActions(final Composite parent) {

		m_editAction = new Action("Edit") {
			@Override
			public void run() {
				super.run();
				MessageDialog.openInformation(parent.getShell(), "Edit", "Edit new song");
			};
		};
		ImageDescriptor descriptor = ResourcesUtils.getImage(EDIT_ACTION_IMAGE_PATH);
		m_editAction.setImageDescriptor(descriptor);
		getViewSite().getActionBars().getToolBarManager().add(m_editAction);

		
	}

	@Override
	public void setFocus() {

	}


	@Override
	public void update(Song songSelected) {
		
		m_songContentLabel.setText("Contents of the " + songSelected.getTitle());
	}
			
}
